home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Source / VersionElems.Mod (.txt) < prev    next >
Encoding:
Oberon Text  |  1995-12-04  |  17.1 KB  |  324 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. BalloonElems
  3. Alloc
  4. Syntax10.Scn.Fnt
  5. "VersionElems"
  6. Version elements simplify the handling of multiple
  7. versions of a module in the same source file.
  8. Text pieces that differ from one version to the
  9. other are enclosed in version elements which look
  10. like angle brackets. When the user middle-clicks
  11. on the opening bracket a popup menu with a list
  12. of version names appears. Selecting one of the
  13. names replaces the bracketed text with the text
  14. that is stored for the selected version.
  15. "Beg"
  16. The opening bracket of a pair of version elements.
  17. When it is clicked at it shows a list of version names.
  18. Selecting one of these names replaces the text
  19. between the Beg and the End element with the
  20. text that is stored for this version name.
  21. "End"
  22. The closing bracket of a pair of version elements.
  23. "CheckMenu"
  24. Makes sure that the variants in the element
  25. are exactly the variants in the popup menu.
  26. "IndexOf"
  27. e.IndexOf(vers) returns the index i so that
  28. e.buf[i] is the text corresponding to vers.
  29. "TwinPos"
  30. e.TwinPos() returns the position of the
  31. corresponding right bracket of e.
  32. "SwitchTo"
  33. e.SwitchTo(vers) switches the element e to
  34. version vers.
  35. "Insert"
  36. VersionElems.Insert name
  37.     Inserts a pair of version elements around the
  38.     current selection. 'name' is the version name.
  39. "SetVersion"
  40. VersionElems.SetVersion name
  41.     Switches all version elements in the marked text
  42.     to version 'name'.
  43. "Find"
  44. VersionElems.Find
  45.     Searches the next version element starting from the
  46.     caret position and sets the caret to this element.
  47. StampElems
  48. Alloc
  49. 4 Dec 95
  50. Syntax10b.Scn.Fnt
  51. Syntax10i.Scn.Fnt
  52. FoldElems
  53. Syntax10.Scn.Fnt
  54.     VAR i: INTEGER;
  55. BEGIN
  56.     i := 0;
  57.     WHILE (i < maxVersions) & (e.vers[i] # "") DO
  58.         IF e.vers[i] = version THEN RETURN i END;
  59.         INC(i)
  60.     END;
  61.     RETURN -1
  62. END IndexOf;
  63. Syntax10.Scn.Fnt
  64.     VAR s: Texts.Scanner; vers: ARRAY maxVersions, 32 OF CHAR; buf: ARRAY maxVersions OF Texts.Buffer; i, j: INTEGER;
  65. BEGIN
  66.     Texts.OpenScanner(s, e.menu, 0); i := 0;
  67.     REPEAT
  68.         Texts.Scan(s);
  69.         IF (i < maxVersions) & (s.class = Texts.Name) THEN
  70.             COPY(s.s, vers[i]);
  71.             j := e.IndexOf(s.s);
  72.             IF j >= 0 THEN buf[i] := e.buf[j] ELSE NEW(buf[i]); Texts.OpenBuf(buf[i]) END;
  73.             INC(i)
  74.         END
  75.     UNTIL s.eot;
  76.     FOR j := 0 TO i-1 DO COPY(vers[j], e.vers[j]); e.buf[j] := buf[j] END;
  77.     IF i < maxVersions THEN e.vers[i] := "" END
  78. END CheckMenu;
  79. Syntax10.Scn.Fnt
  80.     VAR r: Texts.Reader; level: INTEGER;
  81. BEGIN
  82.     Texts.OpenReader(r, Texts.ElemBase(e), Texts.ElemPos(e)+1);
  83.     level := 1;
  84.     LOOP
  85.         Texts.ReadElem(r);
  86.         IF r.eot THEN RETURN -1
  87.         ELSIF r.elem IS Beg THEN INC(level)
  88.         ELSIF r.elem IS End THEN DEC(level);
  89.             IF level = 0 THEN RETURN Texts.Pos(r) - 1 END
  90.         END
  91. END TwinPos;
  92. Syntax10.Scn.Fnt
  93.     VAR t: Texts.Text; beg, end: LONGINT; i, j: INTEGER;
  94. BEGIN
  95.     e.CheckMenu;
  96.     IF version # e.cur THEN
  97.         i := e.IndexOf(version); j := e.IndexOf(e.cur);
  98.         IF i >= 0 THEN
  99.             t := Texts.ElemBase(e); beg := Texts.ElemPos(e) + 1; end := e.TwinPos();
  100.             IF end >= 0 THEN 
  101.                 Texts.Delete(t, beg, end);
  102.                 Texts.Insert(t, beg, e.buf[i]);
  103.                 IF j >= 0 THEN Texts.Recall(e.buf[j]) END;
  104.                 COPY(version, e.cur)
  105.             END
  106.         ELSE Out.String("-- no version "); Out.String(version); Out.F(" at pos #$", Texts.ElemPos(e))
  107.         END
  108. END SwitchTo;
  109. Syntax10.Scn.Fnt
  110. PictElems
  111. Alloc
  112.     VAR line: ARRAY 10 OF SET;
  113. BEGIN
  114.     line[1] := {4};
  115.     line[2] := {3};
  116.     line[3] := {2};
  117.     line[4] := {1};
  118.     line[5] := {0};
  119.     line[6] := {1};
  120.     line[7] := {2};
  121.     line[8] := {3};
  122.     line[9] := {4};
  123.     begIcon := Display.NewPattern(line, 6, 9);
  124.     line[1] := {1};
  125.     line[2] := {2};
  126.     line[3] := {3};
  127.     line[4] := {4};
  128.     line[5] := {5};
  129.     line[6] := {4};
  130.     line[7] := {3};
  131.     line[8] := {2};
  132.     line[9] := {1};
  133.     endIcon := Display.NewPattern(line, 6, 9);
  134. END InitIcons;
  135. Syntax10.Scn.Fnt
  136. END NoNotify;
  137. Syntax10.Scn.Fnt
  138.     VAR r: Texts.Reader; pos: LONGINT; e: Beg;
  139. BEGIN
  140.     Texts.OpenReader(r, t, 0);
  141.     LOOP
  142.         Texts.ReadElem(r);
  143.         IF r.eot THEN EXIT END;
  144.         IF r.elem IS Beg THEN
  145.             pos := Texts.Pos(r) + 1; e := r.elem(Beg); e.SwitchTo(version); Texts.OpenReader(r, t, pos)
  146.         END
  147. END SwitchAll;
  148. Syntax10.Scn.Fnt
  149. Syntax10b.Scn.Fnt
  150.     VAR beg, end, delta: LONGINT;
  151. BEGIN delta := 200;
  152.     LOOP beg := f.org; end := TextFrames.Pos(f, f.X + f.W, f.Y);
  153.         IF (beg <= pos) & (pos < end) OR (delta = 0) THEN EXIT END;
  154.         TextFrames.Show(f, pos - delta); delta := delta DIV 2
  155.     END;
  156.     TextFrames.SetCaret(f, pos)
  157. END ShowPos;
  158. Syntax10m.Scn.Fnt
  159. Syntax10.Scn.Fnt
  160. Syntax10m.Scn.Fnt
  161. Syntax10i.Scn.Fnt
  162.     VAR e1: Beg; i: INTEGER; str: ARRAY 32 OF CHAR; s: Texts.Scanner;
  163. BEGIN
  164.     WITH e: Beg DO
  165.         WITH m: TextFrames.DisplayMsg DO
  166.             IF ~m.prepare THEN
  167.                 Display.CopyPattern(Display.white, begIcon, m.X0, m.Y0+3, Display.paint)
  168.             END
  169.         | m: TextPrinter.PrintMsg DO
  170.             IF m.prepare THEN e.W := 1 ELSE e.W := 7*pixel END
  171.         | m: Texts.CopyMsg DO
  172.             IF m.e = NIL THEN NEW(e1); m.e := e1 ELSE e1 := m.e(Beg) END;
  173.             COPY(e.cur, e1.cur); i := 0;
  174.             WHILE (i < maxVersions) & (e.vers[i] # "") DO
  175.                 COPY(e.vers[i], e1.vers[i]);
  176.                 NEW(e1.buf[i]); Texts.OpenBuf(e1.buf[i]); Texts.Copy(e.buf[i], e1.buf[i]);
  177.                 INC(i)
  178.             END;
  179.             PopupElems.Handle(e, m)
  180.         | m: Texts.IdentifyMsg DO
  181.             m.mod := "VersionElems"; m.proc := "AllocBeg"
  182.         | m: Texts.FileMsg DO
  183.             PopupElems.Handle(e, m);
  184.             IF m.id = Texts.load THEN
  185.                 Files.ReadString(m.r, e.cur);
  186.                 Files.ReadString(m.r, str); i := 0;
  187.                 WHILE str # "" DO
  188.                     COPY(str, e.vers[i]);
  189.                     Texts.Load(m.r, scratch); Texts.Delete(scratch, 0, scratch.len);
  190.                     NEW(e.buf[i]); Texts.Recall(e.buf[i]);
  191.                     INC(i); Files.ReadString(m.r, str)
  192.                 END
  193.             ELSE (*Texts.store*)
  194.                 Files.WriteString(m.r, e.cur); i := 0;
  195.                 WHILE (i < maxVersions) & (e.vers[i] # "") DO
  196.                     Files.WriteString(m.r, e.vers[i]);
  197.                     Texts.Append(scratch, e.buf[i]); Texts.Store(m.r, scratch);
  198.                     Texts.Delete(scratch, 0, scratch.len); Texts.Recall(e.buf[i]);
  199.                     INC(i)
  200.                 END;
  201.                 Files.WriteString(m.r, "")
  202.             END
  203.         | m: PopupElems.ExecMsg DO
  204.             Texts.OpenScanner(s, e.menu, m.pos); Texts.Scan(s);
  205.             IF s.class = Texts.Name THEN SwitchAll(Texts.ElemBase(e), s.s) END
  206.         ELSE PopupElems.Handle(e, m)
  207.         END
  208. END HandleBeg;
  209. Syntax10.Scn.Fnt
  210. Syntax10m.Scn.Fnt
  211.     VAR e1: End; keys: SET; x, y: INTEGER;
  212. BEGIN
  213.     WITH e: End DO
  214.         WITH m: TextFrames.DisplayMsg DO
  215.             IF ~m.prepare THEN
  216.                 Display.CopyPattern(Display.white, endIcon, m.X0, m.Y0+3, Display.paint)
  217.             END
  218.         | m: TextPrinter.PrintMsg DO
  219.             IF m.prepare THEN e.W := 1 ELSE e.W := 7*pixel END
  220.         | m: Texts.CopyMsg DO
  221.             IF m.e = NIL THEN NEW(e1); m.e := e1 ELSE e1 := m.e(End) END;
  222.             Texts.CopyElem(e, e1)
  223.         | m: Texts.IdentifyMsg DO
  224.             m.mod := "VersionElems"; m.proc := "AllocEnd"
  225.         | m: TextFrames.TrackMsg DO
  226.             IF m.keys = {MM} THEN
  227.                 REPEAT
  228.                     Input.Mouse(keys, x, y); Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  229.                 UNTIL keys = {}
  230.             END
  231.         ELSE
  232.         END
  233. END HandleEnd;
  234. Syntax10.Scn.Fnt
  235.     VAR e: Beg;
  236. BEGIN
  237.     NEW(e); e.handle := HandleBeg; Texts.new := e
  238. END AllocBeg;
  239. Syntax10.Scn.Fnt
  240.     VAR e: End;
  241. BEGIN
  242.     NEW(e); e.handle := HandleEnd; Texts.new := e
  243. END AllocEnd;
  244. Syntax10.Scn.Fnt
  245.     VAR a: Beg; b: End; t: Texts.Text; beg, end, time: LONGINT; s: Texts.Scanner;
  246. BEGIN
  247.     Oberon.GetSelection(t, beg, end, time);
  248.     IF time >= 0 THEN
  249.         Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
  250.         IF s.class = Texts.Name THEN
  251.             NEW(a);
  252.             a.W := 7*pixel; a.H := 11*pixel; a.handle := HandleBeg; COPY(s.s, a.cur);
  253.             a.menu := TextFrames.Text("");
  254.             Texts.WriteString(w, s.s); Texts.Append(a.menu, w.buf); PopupElems.MeasureMenu(a);
  255.             Texts.WriteElem(w, a); Texts.Insert(t, beg, w.buf);
  256.             NEW(b);
  257.             b.W := 7*pixel; b.H := 11*pixel; b.handle := HandleEnd;
  258.             Texts.WriteElem(w, b); Texts.Insert(t, end+1, w.buf)
  259.         ELSE Out.String("-- version name must be an Oberon name$")
  260.         END
  261.     ELSE Out.String("-- no selection$")
  262. END Insert;
  263. Syntax10.Scn.Fnt
  264.     VAR version: ARRAY 32 OF CHAR; v: Viewers.Viewer; t: Texts.Text;
  265. BEGIN
  266.     In.Open; In.Name(version);
  267.     IF In.Done THEN
  268.         v := Oberon.MarkedViewer();
  269.         IF (v # NIL) & (v.dsc.next # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  270.             t := v.dsc.next(TextFrames.Frame).text;
  271.             SwitchAll(t, version)
  272.         END
  273.     ELSE Out.String("-- version name must be an Oberon name$")
  274. END SetVersion;
  275. Syntax10.Scn.Fnt
  276.     VAR v: Viewers.Viewer; f: TextFrames.Frame; r: Texts.Reader; pos: LONGINT;
  277. BEGIN
  278.     v := Oberon.FocusViewer;
  279.     IF (v # NIL) & (v.dsc.next # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  280.         f := v.dsc.next(TextFrames.Frame);
  281.         IF f.hasCar THEN pos := f.carloc.pos ELSE pos := 0 END;
  282.         Texts.OpenReader(r, f.text, pos);
  283.         REPEAT Texts.ReadElem(r) UNTIL r.eot OR (r.elem IS Beg);
  284.         IF ~r.eot THEN ShowPos(f, Texts.Pos(r)) ELSE TextFrames.RemoveCaret(f) END
  285. END Find;
  286. MODULE VersionElems;    
  287.     (* HM 14 Sep 95 / 
  288. IMPORT Display, Viewers, Files, Input, Texts, TextFrames, TextPrinter, Oberon, PopupElems, In, Out;
  289. CONST
  290.     maxVersions = 8;
  291.     pixel = LONG(10000);
  292.     ML = 2; MM = 1; MR = 0;
  293.     Beg* = POINTER TO BegDesc;
  294.     BegDesc* = RECORD (PopupElems.ElemDesc)
  295.         cur: ARRAY 32 OF CHAR;    (*current version*)
  296.         vers: ARRAY maxVersions, 32 OF CHAR;    (*version names*)
  297.         buf: ARRAY maxVersions OF Texts.Buffer    (*version texts*)
  298.     END;
  299.     End* = POINTER TO EndDesc;
  300.     EndDesc* = RECORD (Texts.ElemDesc) END;
  301.     begIcon, endIcon: Display.Pattern;    (* x = 0, y = 3, w = 6, h = 9 *)
  302.     scratch: Texts.Text;
  303.     w: Texts.Writer;
  304. PROCEDURE (e: Beg) IndexOf (version: ARRAY OF CHAR): INTEGER;    
  305. PROCEDURE (e: Beg) CheckMenu;    
  306. PROCEDURE (e: Beg) TwinPos (): LONGINT;    
  307. PROCEDURE (e: Beg) SwitchTo (version: ARRAY OF CHAR);    
  308. PROCEDURE InitIcons;    
  309. PROCEDURE NoNotify (t: Texts.Text; op: INTEGER; beg, end: LONGINT);    
  310. PROCEDURE SwitchAll (t: Texts.Text; version: ARRAY OF CHAR);    
  311. PROCEDURE ShowPos (f: TextFrames.Frame; pos: LONGINT);    
  312. PROCEDURE HandleBeg* (e: Texts.Elem; VAR m: Texts.ElemMsg);    
  313. PROCEDURE HandleEnd* (e: Texts.Elem; VAR m: Texts.ElemMsg);    
  314. PROCEDURE AllocBeg*;    
  315. PROCEDURE AllocEnd*;    
  316. PROCEDURE Insert*;    
  317. PROCEDURE SetVersion*;    
  318. PROCEDURE Find*;    
  319. BEGIN
  320.     InitIcons;
  321.     Texts.OpenWriter(w);
  322.     NEW(scratch); Texts.Open(scratch, ""); scratch.notify := NoNotify
  323. END VersionElems.
  324.